package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbUserMapper;
import com.bw1806.pojo.TbUser;
import com.bw1806.pojo.TbUserExample;
import com.bw1806.sellergoods.service.TbUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbUserServiceImpl implements TbUserService {

    @Autowired
    private TbUserMapper tbUserMapper;

    @Override
    public List<TbUser> findAll() {
        return tbUserMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbUser> pagelist(TbUser tbUser,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbUserExample example=new TbUserExample();

        TbUserExample.Criteria criteria = example.createCriteria();

        if(tbUser!=null){
            //if(tbUser.getName()!=null && tbUser.getName().length()>0){
            //    criteria.andNameLike("%"+tbUser.getName()+"%");
           // }
        }

        Page<TbUser> page= (Page<TbUser>) tbUserMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbUser tbUser) {
        Long id = tbUser.getId();
        if(id != null && id !=0){
            tbUserMapper.updateByPrimaryKey(tbUser);
        } else{
            tbUserMapper.insert(tbUser);
        }
    }

    @Override
    public TbUser getById(Long id) {
        return tbUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbUserMapper.deleteByPrimaryKey(id);
        }
        //tbUserMapper.deletebth(ids);
    }
}
